package com.ninghushangbao.ninghu.controller;

import com.ninghushangbao.ninghu.controller.vo.ResultEntity;
import com.ninghushangbao.ninghu.entity.News;
import com.ninghushangbao.ninghu.service.NewsService;
import com.ninghushangbao.ninghu.utils.BaseResult.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
@CrossOrigin()
public class NewsController {

    @Autowired
    NewsService newsService;

    @PostMapping("/news_add")
    public ResultEntity newsAdd(@RequestBody News news){
        newsService.addNews(news);
        return ResultUtil.success();
    }

    @GetMapping("/sel_all")
    public ResultEntity newSelect(){
        List news = newsService.selectNews();
        return ResultUtil.success(news);
    }

    @PutMapping("/news_update")
    public ResultEntity newsUpdate(@RequestBody News news){
        System.out.println(news);
        newsService.updateNews(news);
        return ResultUtil.success();
    }

    @DeleteMapping("news_del")
    public ResultEntity newsDelete(@RequestBody List<Integer> newsId){
        newsService.deleteNewsById(newsId);
        return ResultUtil.success();
    }

}
